package com.hxb.example.resp;

import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;

@Data
@NoArgsConstructor
@EqualsAndHashCode
public class ApiResponse<T> {

    private boolean success;

    private String msg;

    private T data;

    public ApiResponse(boolean success, String msg) {
        this.success = success;
        this.msg = msg;
    }

    public static <T> ApiResponse<T> fail(String msg) {
        return new ApiResponse<T>(false, msg);
    }

    public static <T> ApiResponse<T> success(T data) {
        ApiResponse<T> response = new ApiResponse<T>(true, "成功");
        response.setData(data);
        return response;
    }

}
